package com.baige.api.app.controller;

import com.baige.api.app.sdk.request.MessageListRequest;
import com.baige.api.app.sdk.response.MessageResponse;
import com.baige.api.app.sdk.response.NewestMessageResponse;
import com.baige.common.core.BaseResponse;
import com.baige.common.core.MsgResponse;
import com.baige.common.core.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author wulg
 * @date 2018/12/13.
 */
@Api(value = "SystemMessageController", description = "系统消息接口", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/api/rest/system/message")
public class SystemMessageController
{

    private static final Logger logger = LoggerFactory.getLogger(SystemMessageController.class);

    /**
     * 获取用户某种类型的消息列表
     *
     * @param userId      用户id
     * @param type        消息类型
     * @param requestParams 请求参数
     * @param bindingResult 参数校验
     * @return List<MessageResponse>
     */
    @RequestMapping(value = "/v1/{userId}/type/{type}", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "获取用户某种类型的消息列表", notes = "获取用户某种类型的消息列表", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<List<MessageResponse>> getMessageListByType(@ApiParam(value = "用户id") @PathVariable("userId") String userId, @ApiParam(value = "类型(1.系统消息、2.活动消息)") @PathVariable("type") int type, @ModelAttribute @Valid MessageListRequest requestParams, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.error("获取用户某种类型的消息列表参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }

    /**
     * 获取用户最新消息
     *
     * @param userId 用户id
     * @return Result<NewestMessageResponse>
     */
    @RequestMapping(value = "/v1/{userId}/newest", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "获取用户最新消息", notes = "获取用户最新消息", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<NewestMessageResponse> getNewestMessage(@ApiParam(value = "用户id") @PathVariable("userId") String userId) {
        return null;
    }

    /**
     * 修改用户信息状态
     *
     * @param userId 用户id
     * @param type   消息类型
     * @return Result<MsgResponse>
     */
    @RequestMapping(value = "/v1/{userId}/type/{type}", method = RequestMethod.PUT, produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "修改用户信息状态", notes = "修改用户信息状态", httpMethod = "PUT", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<MsgResponse> modifyMessageStatus(@ApiParam(value = "用户id") @PathVariable("userId") String userId, @ApiParam(value = "类型(1.系统消息、2.活动消息)") @PathVariable("type") int type) {
        return null;
    }
}
